<?php require_once('header.php'); ?>

<div id="search_filter">
	<a href="/admin/user">all</a> | <a href="/admin/user">inactive</a> | <a href="/admin/user">blocked</a>
</div>

<?php if(isset($error)): ?>
	<div id="error"><?=$error?></div>
<?php endif; ?>

<h1>User administration</h1>

<div id="search_filter">
	<?=form_open('/admin/user')?>
    <table><tr style="vertical-align:bottom;">
    	<td>id<br />
    	<?php 
    		$data = array(
              'name'        => 'id',
              'id'          => 'id',
              'value'       => $post['id'],
              'maxlength'   => '',
              'size'        => '5',
              'style'       => '',
            );
			echo form_input($data);
		?>
    	</td>
    	<td>user<br />
    	<?php 
    		$data = array(
              'name'        => 'usr',
              'id'          => 'usr',
              'value'       => $post['usr'],
              'maxlength'   => '',
              'size'        => '30',
              'style'       => '',
            );
			echo form_input($data);
		?>
    	</td>
        <td>email<br />
		<?php 
    		$data = array(
              'name'        => 'email',
              'id'          => 'email',
              'value'       => $post['email'],
              'maxlength'   => '',
              'size'        => '30',
              'style'       => '',
            );
			echo form_input($data);
		?>
		</td>
		<td>OR <?=form_radio('filter_condition', 'OR', (! isset($post['filter_condition']) || $post['filter_condition']=='OR')?TRUE:FALSE)?></td>
		<td>AND <?=form_radio('filter_condition', 'AND', (isset($post['filter_condition']) && $post['filter_condition']=='AND')?TRUE:FALSE)?></td>
		<td>% <?=form_checkbox('filter_wildcard', 'LIKE', (isset($post['filter_wildcard']))?TRUE:FALSE)?>
		</td>
        <td><?=form_submit('filter_submit', 'Filter users!')?></td>
    </tr></table>
    <?=form_close()?>
</div>

<div id="resultContainer">
<table id="resultsTable">
<tr class="th">
	<td>id</td>
	<td>type</td>
	<td>username</td>
	<td>email</td>
	<td>first name</td>
	<td>middle name</td>
	<td>last_name</td>
	<td>alias</td>
	<td>nationality</td>
	<td>location</td>
	<td>avatar</td>
	<td>date_registration</td>
	<td>date_lastvisit</td>
	<td>activation</td>
	<td style="width:30px;">&nbsp;</td>
	<td style="width:30px;">&nbsp;</td>
	<td style="width:30px;">&nbsp;</td>
	<td style="width:30px;">&nbsp;</td>
</tr>
<?php $i = 0; foreach($users as $user): ?>
<tr <?php if(($i++)%2) echo ' class="boldLine"';?>>
	<td><?=$user->id?></td>
	<td><?=$user_types[$user->reftype_user]?></td>
	<td><?=$user->usr?></td>
	<td><?=$user->email?></td>
	<td><?=$user->first_name?></td>
	<td><?=$user->middle_name?></td>
	<td><?=$user->last_name?></td>
	<td><?=$user->alias?></td>
	<td><?=$user->nationality?></td>
	<td><?=$user->location?></td>
	<td><?=$user->avatar?></td>
	<td><?=$user->date_registration?></td>
	<td><?=$user->date_lastvisit?></td>
	<td><?=$user->activation?></td>
	
	<?php 
		if($user->is_active)
		{
			$image_active		= 'enabled';
			$alt_active			= 'Disable user';
			$new_status_active	= 0; 
		}
		else 
		{
			$image_active		= 'disabled';
			$alt_active			= 'Enable user';
			$new_status_active	= 1; 
		}
		
		if($user->is_blocked)
		{
			$image_blocked		= 'enabled';
			$alt_blocked		= 'Unblock user';
			$new_status_blocked	= 0; 
		}
		else 
		{
			$image_blocked		= 'disabled';
			$alt_blocked		= 'Block user';
			$new_status_blocked	= 1; 
		}
	?>
	
	<td><a href="/admin/user/switch_user_lock/<?=$user->id?>/<?=$new_status_blocked?>"><img src="/images/template/icon/icon-blocked-<?=$image_blocked?>.png" alt="<?=$alt_blocked?>" title="<?=$alt_blocked?>" /></a></td>
	<td><a href="/admin/user/switch_user_activation/<?=$user->id?>/<?=$new_status_active?>"><img src="/images/template/icon/icon-active-<?=$image_active?>.png" alt="<?=$alt_active?>" title="<?=$alt_active?>" /></a></td>
	<td><a href="/admin/user/edit/<?=$user->id?>"><img src="/images/template/icon/icon-modify.png" alt="Modify user" title="Modify user" /></a></td>
	<td><a href="/admin/user/delete/<?=$user->id?>"><img src="/images/template/icon/icon-trash.png" alt="Delete user" title="Delete user" /></a></td>
</tr>
<?php endforeach;?>
</table>
</div><br/>

<h2>New user registration</h2>

<?php echo form_open('/admin/user/insert'); ?>
<table>
	<tr>
		<td><?=form_label('User type', 'reftype_user')?></td>
		<td><?=form_dropdown('reftype_user', $user_types, 1)?></td>
	</tr>
	<tr>
		<td><?=form_label('Username', 'username')?></td>
		<td><?=form_input('usr', '')?></td>
	</tr>
	<tr>
		<td><?=form_label('Password', 'password')?></td>
		<td><?=form_input('pwd', '')?></td>
	</tr>
	<tr>
		<td><?=form_label('Email', 'email')?></td>
		<td><?=form_input('email', '')?></td>
	</tr>
	<tr>
		<td><?=form_label('First name', 'first_name')?></td>
		<td><?=form_input('first_name', '')?></td>
	</tr>
	<tr>
		<td><?=form_label('Middle name', 'middle_name')?></td>
		<td><?=form_input('middle_name', '')?></td>
	</tr>
	<tr>
		<td><?=form_label('Last name', 'last_name')?></td>
		<td><?=form_input('last_name', '')?></td>
	</tr>
	<tr>
		<td><?=form_label('Alias', 'alias')?></td>
		<td><?=form_input('alias', '')."<br/>"?></td>
	</tr>
	<tr>
		<td><?=form_label('Nationality', 'nationality')?></td>
		<td><?=form_input('nationality', '')?></td>
	</tr>
	<tr>
		<td><?=form_label('Location', 'location')?></td>
		<td><?=form_input('location', '')?></td>
	</tr>
	<tr>
		<td><?=form_label('Avatar', 'avatar')?></td>
		<td><?=form_input('avatar', '')?></td>
	</tr>
	<tr>
		<td><?=form_submit('submit', 'Create user!')?></td>
		<td>&nbsp;</td>
	</tr>
</table>
<?php echo form_close(); ?>

<?php require_once('footer.php'); ?>